<?php
class topmenuWidget extends CWidget
{
	public $clientScript;
		
	public $baseUrl;
	//javascript 库
	public $Jscripts = array();
	
	public $Cssscript = 'topmenu.css';


   /**
    * Publishes the assets
    */
   public function publishAssets()
   {
      $dir = dirname(__FILE__).DIRECTORY_SEPARATOR.'assets'; 
      $this->baseUrl = Yii::app()->getAssetManager()->publish($dir);
   }
   
   /**
    * Registers the external javascript files
    */
   public function registerClientScripts()
   {
      if ($this->baseUrl === '')
         throw new CException('Can not find the base folder');

      $this->clientScript = Yii::app()->getClientScript();
      
      $this->clientScript->registerCoreScript('jquery');

      foreach ($this->Jscripts as $script)
      {
      	$this->clientScript->registerScriptFile($this->baseUrl.'/js/'.$script,CClientScript::POS_BEGIN);     	
      }      
      
      $this->clientScript->registerCssFile($this->baseUrl.'/css/'.$this->Cssscript);
   }
   
   public function registerScript()
   {
   		$script = <<<SCRIPT
		   	$("#topnav li").prepend("<span></span>");
			$("#topnav li").each(function() {
				var linkText = $(this).find("a").html();
				$(this).find("span").show().html(linkText);
			});
			$("#topnav li").hover(function() {
				$(this).find("span").stop().animate({
					marginTop: "-60"
				},
				250);
			},
			function() {
				$(this).find("span").stop().animate({
					marginTop: "0"
				},
				250);
			});
   		
			$(".menuMore").hover(function(){
   				parallax.menuList.hoverShow($(this));
			},function(){
    			parallax.menuList.hoverHide();
   		
			});
SCRIPT;
		$this->clientScript->registerScript('topmenuWidget',$script,CClientScript::POS_READY);
		
   }
   


  
	public function run()
	{

		$this->publishAssets();
		$this->registerClientScripts();
		$this->registerScript();
		
		$this->render('topmenu');
	}

}
?>